package com.cnam.alsace.smcl.server;

import java.util.ArrayList;
import java.util.List;

import org.restlet.resource.ServerResource;

import com.cnam.alsace.smcl.model.User;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;

public class UserController extends ServerResource implements
		UserControllerInterface {

	public UserController() {
	}

	@Override
	public void create(User user) {
		ObjectifyService.register(User.class);
		Objectify ofy = ObjectifyService.begin();

		User tp = new User();
		tp.setM_pseudo((user.getM_pseudo()));
		tp.setM_score((user.getM_score()));
		ofy.put(tp);
	}

	@Override
	public Container getAllUsers() {
		Container content = null;
		List<User> users = new ArrayList<User>();
		ObjectifyService.register(User.class);
		Objectify ofy = ObjectifyService.begin();

		Query<User> q = ofy.query(User.class);

		for (User u : q)
			users.add(u);

		content = new Container();
		content.setUser_list(users);

		return content;
	}

}
